package com.qigao.mall.web.controller.app.user;

import com.github.pagehelper.PageInfo;
import com.qigao.mall.api.AccountLogService;
import com.qigao.mall.commons.dto.AccountLogCondDto;
import com.qigao.mall.commons.dto.AccountLogResultDto;
import com.qigao.mall.commons.enums.Result;
import com.qigao.mall.commons.enums.ResultCode;
import com.qigao.mall.web.utils.RequestUtils;
import com.qigao.mall.web.vo.admin.merchant.AccountLogCondVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author luiz
 * @Title: com.qigao.mall.web.controller.app.merchant
 * @ProjectName three-mall
 * @date 2020-04-2020/4/13 9:58
 * @Description:账户资金流水相关
 */
@RestController
@RequestMapping("/app/user/accountLog/")
@Api(tags = "APP个人中心账单")
public class AppAccountLogController {
    private static Logger logger= LoggerFactory.getLogger(AppAccountLogController.class);
    @Resource
    AccountLogService accountLogService;
    @PostMapping("/listPage")
    @ApiOperation(value = "账户资金流水分页查询列表", notes = "账户资金流水分页查询列表")
    public Result<PageInfo<AccountLogResultDto>> listPage(@RequestBody AccountLogCondVo accountLogCondVo, HttpServletRequest request){
        try{
            //参数校验
            AccountLogCondDto accountLogCondDto=new AccountLogCondDto();
            BeanUtils.copyProperties(accountLogCondVo,accountLogCondDto);
            accountLogCondDto.setUserNo(RequestUtils.getCurrentUserNo(request));
            if(StringUtils.isNotEmpty(accountLogCondVo.getStartDate())){
                accountLogCondDto.setStartDate(accountLogCondVo.getStartDate()+" 00:00:00");
            }
            if(StringUtils.isNotEmpty(accountLogCondVo.getEndDate())){
                accountLogCondDto.setEndDate(accountLogCondVo.getEndDate()+" 23:59:59");
            }
            return  accountLogService.listPage(accountLogCondDto);
        }catch (Exception e){
            logger.error("[账户资金流水分页查询列表]发生异常:{}",e);
            return Result.newError(ResultCode.FAIL);
        }
    }

}
